//
//  XQTopCardView.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/20.
//

#import "XQTopCardView.h"

@interface XQTopCardView()
@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UIImageView *logoImageView;
@property (nonatomic,strong) UILabel *nameLb;
@end

@implementation XQTopCardView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)makeUI{
    [self addSubview:self.imageView];
    [self.imageView addSubview:self.logoImageView];
    [self.imageView addSubview:self.nameLb];
}

- (void)makeConstraints {
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.height.mas_equalTo(220);
        make.bottom.equalTo(@0);
    }];
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        (void)make.centerX;
        make.top.equalTo(@42);
        make.width.height.equalTo(@90);
    }];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.logoImageView.mas_bottom).offset(11);
        make.centerX.equalTo(self.logoImageView);
    }];
}

#pragma mark - setter

- (void)setImageName:(NSString *)imageName {
    [self.logoImageView sd_setImageWithURL:[NSURL URLWithString:imageName] placeholderImage:[UIImage imageNamed:@"logo"]];
}

- (void)setAvatarImageName:(NSString *)avatarImageName {
    self.logoImageView.image = [UIImage imageNamed:avatarImageName];
}

- (void)setNick:(NSString *)nick {
    self.nameLb.text = nick;
}

- (void)setNickColor:(UIColor *)nickColor {
    self.nameLb.textColor = nickColor;
}

- (void)setNickFont:(CGFloat)nickFont {
    self.nameLb.font = [UIFont boldSystemFontOfSize:nickFont];;
}

- (void)setPadding:(CGFloat)padding {
    [self.nameLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.logoImageView.mas_bottom).offset(padding);
    }];
}

#pragma mark - lazy

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.image = [UIImage imageNamed:@"top_card_bg"];
    }
    return _imageView;
}

- (UIImageView *)logoImageView {
    if (!_logoImageView) {
        _logoImageView = [[UIImageView alloc] init];
        _logoImageView.image = [UIImage imageNamed:@"logo"];
    }
    return _logoImageView;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [[UILabel alloc] init];
        _nameLb.textColor = [UIColor colorWithHexString:@"#D8EBFF"];
        _nameLb.font = [UIFont boldSystemFontOfSize:20];
    }
    return _nameLb;
}

@end
